<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="../common/common.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>我的队伍</title>
<script type="text/javascript">
	$(function(){
		//关闭窗口
		close();
		
		$("#submitBtn").on("click",function(){
			saveTeam();
		});
		$("#colseBtn").on("click",function(){
			close();
		});
		
		
		$.ajax({
			type:"POST",
			url:"<%=basePath%>team/toMyTeam",
			success : function(result) {

			},
			error : function(result) {
				alert("error");
			}
		});
	});
	
	//打开创建队伍窗口
	function addTeam(){
		$("#modal").show();
	}
	
	//创建队伍
	function saveTeam(){
		
		var code_i = $.trim($("#code_i").val());
		var name_i = $.trim($("#name_i").val());
		
		
		$.ajax({
			type:"POST",
			url:"<%=basePath%>team/addTeam",
			data:{"code":code_i,"name":name_i},
			success : function(result) {
				if(result.success){
					alert("创建队伍成功!");
					//关闭窗口
					close();
					
					//TODO 把队伍信息显示出来
				}else{
					
					alert(result.errorMsg);
				}
			},
			error : function(result) {
				alert("error");
			}
		})
	}
	
	
	//离开队伍
	function leaveTeam(){
		$.ajax({
			type:"POST",
			url:"<%=basePath%>team/leaveTeam",
			success : function(result) {
				if(result.success){
					alert("离开队伍成功!");
				}else{
					
					alert(result.errorMsg);
				}
			},
			error : function(result) {
				alert("error");
			}
		});
	}
	
	//邀请他人加入 
	function inviteMember(){
		//TODO 打开二维码界面让别人扫码
		
		$.ajax({
			type:"POST",
			url:"<%=basePath%>team/getInviteQRCode",
			success : function(result) {
				if(result.success){
					alert(result.url);
				}else{
					
					alert(result.errorMsg);
				}
			},
			error : function(result) {
				alert("error");
			}
		});
		
	}
	
	//加入队伍
	function joinTeam(){
		//TODO 打开摄像头扫码 
		//扫描类似 localhost:8080/crm/team/joinTeam?teamId=16&&timeStamp=1452838130654&&validateCode=66zNa99b2cNad7N77096aNa3xe3abz3d 的二维码
	}
	
	//关闭窗口
	function close(){
		$("#modal").hide();
	}
	
	function myTeammate(){
		location.href="<%=basePath%>team/toMyTeammate";
	}
	
	
	
</script>
</head>
<body>
	<button id="myTeammateBtn" name="myTeammateBtn" onclick="myTeammate()">我的队友</button>

	<button id="addTeamBtn" name="addTeamBtn" onclick="addTeam()">创建队伍</button>
	<br/>
	<button id="joinTeamBtn" name="joinTeamBtn" onclick="joinTeam()">加入队伍</button>
	<br />
	
	<button id="inviteMemberBtn" name="inviteMemberBtn" onclick="inviteMember()">邀请他人加入</button>
	<br />
	<button id="leaveTeamBtn" name="leaveTeamBtn" onclick="leaveTeam()">离开队伍</button>
	<br /> 队伍编码:
	<input type="text" id="code" name="code" value="${team.code}" readOnly="true" maxlength="32" />
	<br /> 队伍名称:
	<input type="text" id="name" name="name" value="${team.name}" readOnly="true" maxlength="32" />
	<br />

	<div id="modal">
		<div class="modal-header">
			<h4 class="modal-title" id="myModalLabel">创建队伍</h4>
		</div>
		<div class="modal-body">
			<form id="form">
				<div class="form-group">
					<label for="code_i" class="col-sm-2 control-label">队伍编码</label>
					<div class="col-sm-10">
						<input type="text" class="form-control" id="code_i" name="code_i" placeholder="请输入队伍编码">
					</div>
				</div>
				<div class="form-group">
					<label for="name_i" class="col-sm-2 control-label">队伍名称</label>
					<div class="col-sm-10">
						<input type="text" class="form-control" id="name_i" name="name_i" placeholder="请输入队伍名称">
					</div>
				</div>


				<div class="modal-footer">
					<!-- data-dismiss="modal" 关闭模态框 -->
					<button id="submitBtn" type="button" class="btn btn-primary">提交</button>
					<button id="colseBtn" type="button" class="btn btn-default">关闭</button>
				</div>
			</form>
		</div>
	</div>

</body>
</html>